import { _decorator, Component, Node, Size, UITransform, view } from 'cc';
import { AppControll } from '../manager/AppControll';
const { ccclass, property } = _decorator;

@ccclass('CommunityBtn')
export class CommunityBtn extends Component {
    protected onLoad(): void {

    }

    ConverPos(node: Node): any {
        let rSize = { x: 0, y: 0, width: 0, height: 0 };
        //获取小游戏屏幕像素分辨率
        let size = view.getFrameSize();
        let vSize = view.getVisibleSize();
        let nodeSize = new Size(20, 20)

        //获取目标Y轴位置在总分辨率比例
        let tempY = 0.5 - node.position.y / vSize.height;
        let tempX = 0.5 + node.position.x / vSize.width;
        rSize.x = size.width * tempX - nodeSize.width / 2;
        rSize.y = size.height * tempY - nodeSize.height / 2;
        rSize.width = nodeSize.width;
        rSize.height = nodeSize.height;
        return rSize;
    }

    start() {
        this.scheduleOnce(() => {
            AppControll.Platform.CreaterClubBtn(this.ConverPos(this.node));
        })
    }

    update(deltaTime: number) {

    }

    protected onDestroy(): void {
        AppControll.Platform.HideClubBtn();
    }
}


